home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / walker / models.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  18KB  |  694 lines

  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7.  
  8. #include "walker.h"
  9.  
  10.  
  11.   /* for cube models */
  12. #define UPPER_LEG_SIZE_C 0.45
  13. #define LOWER_LEG_SIZE_C 0.45
  14. #define UPPER_ARM_SIZE_C 0.4
  15. #define LOWER_ARM_SIZE_C 0.4
  16. #define FOOT_SIZE_C 0.2
  17. #define HEAD_SIZE_C 0.25
  18. #define TORSO_HEIGHT_C 0.8
  19. #define TORSO_WIDTH_C 0.5
  20. #define LEG_GIRTH_C 0.1
  21. #define ARM_GIRTH_C 0.05
  22.  
  23.   /* for cylinder models */
  24. #define UPPER_LEG_SIZE 0.5
  25. #define LOWER_LEG_SIZE 0.5
  26. #define LEG_GIRTH 0.08
  27. #define UPPER_LEG_GIRTH 0.1
  28. #define UPPER_LEG_TAPER 0.8
  29. #define LOWER_LEG_TAPER 0.8
  30. #define LOWER_LEG_GIRTH 0.07
  31.  
  32. #define UPPER_ARM_SIZE 0.45
  33. #define LOWER_ARM_SIZE 0.45
  34. #define ARM_GIRTH 0.05
  35. #define UPPER_ARM_GIRTH 0.05
  36. #define LOWER_ARM_GIRTH 0.04
  37. #define UPPER_ARM_TAPER 0.8
  38. #define LOWER_ARM_TAPER 0.8
  39.  
  40. #define HIP_JOINT_SIZE 0.1
  41. #define KNEE_JOINT_SIZE 0.09
  42. #define SHOULDER_JOINT_SIZE 0.05
  43. #define ELBOW_JOINT_SIZE 0.045
  44.  
  45. #define HEAD_SIZE 0.2
  46. #define FOOT_SIZE 0.15
  47.  
  48. #define TORSO_HEIGHT 0.8
  49. #define TORSO_WIDTH 0.35
  50. #define TORSO_TAPER 0.7
  51.  
  52. #define STACKS 10
  53. #define SLICES 10
  54.  
  55. #define NUM_BODY_PARTS 7
  56.  
  57.  
  58. #define LEFT 0
  59. #define RIGHT 1
  60. #define SOLID 1
  61. #define WIRE 0
  62.  
  63.  
  64.  
  65. void DrawTheGuy_WC(void);
  66. void DrawTheGuy_SC(void);
  67. void draw_head_C(int solid);
  68. void draw_torso_C(int solid);
  69. void draw_leg_C(int which, int solid);
  70. void draw_arm_C(int which, int solid);
  71.  
  72. void StoreTheGuy_SL(void);
  73. void DrawTheGuy_SL(void);
  74. void draw_head_SL(void);
  75. void draw_torso_SL(void);
  76. void draw_leg_SL(int which);
  77. void draw_arm_SL(int which);
  78. void store_head_SL(void);
  79. void store_torso_SL(void);
  80. void store_uleg_SL(void);
  81. void store_lleg_SL(void);
  82. void store_foot_SL(void);
  83. void store_uarm_SL(void);
  84. void store_larm_SL(void);
  85.  
  86. void StoreTheGuy_SL2(void);
  87. void DrawTheGuy_SL2(void);
  88. void draw_head_SL2(void);
  89. void draw_torso_SL2(void);
  90. void draw_leg_SL2(int which);
  91. void draw_arm_SL2(int which);
  92. void store_head_SL2(void);
  93. void store_torso_SL2(void);
  94. void store_uleg_SL2(void);
  95. void store_lleg_SL2(void);
  96. void store_foot_SL2(void);
  97. void store_uarm_SL2(void);
  98. void store_larm_SL2(void);
  99.  
  100. /**************************************************************/
  101. void DrawTheGuy_WC(void)
  102. {
  103.   draw_head_C(WIRE);
  104.   draw_torso_C(WIRE);
  105.   draw_leg_C(LEFT,  WIRE);
  106.   draw_leg_C(RIGHT, WIRE);
  107.   draw_arm_C(LEFT,  WIRE);
  108.   draw_arm_C(RIGHT, WIRE);
  109. }
  110.  
  111. /**************************************************************/
  112. void DrawTheGuy_SC(void)
  113. {
  114.   GLfloat head_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  115.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  116.   GLfloat leg_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  117.   GLfloat arm_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  118.  
  119.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  120.   draw_head_C(SOLID);
  121.  
  122.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  123.   draw_torso_C(SOLID);
  124.  
  125.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  126.   draw_leg_C(LEFT,  SOLID);
  127.   draw_leg_C(RIGHT, SOLID);
  128.  
  129.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  130.   draw_arm_C(LEFT,  SOLID);
  131.   draw_arm_C(RIGHT, SOLID);
  132. }
  133.  
  134.  
  135.  
  136. /**********************************************************/
  137. void draw_head_C(int solid)
  138. {
  139.   glPushMatrix();
  140.   glColor3f(1.0, 1.0, 0.0);
  141.   glTranslatef(0.0, TORSO_HEIGHT_C+(HEAD_SIZE_C/1.5), 0.0);
  142.   glScalef(HEAD_SIZE_C, HEAD_SIZE_C, LEG_GIRTH_C);
  143.   if (solid)
  144.     glutSolidCube(1.0);
  145.   else
  146.     glutWireCube(1.0);
  147.   glPopMatrix();
  148. }
  149.  
  150. /**********************************************************/
  151. void draw_torso_C(int solid)
  152. {
  153.   glPushMatrix();
  154.   glColor3f(0.0, 1.0, 1.0);
  155.   glTranslatef(0.0, TORSO_HEIGHT_C/2.0, 0.0);
  156.   glScalef(TORSO_WIDTH_C, TORSO_HEIGHT_C, LEG_GIRTH_C);
  157.   if (solid)
  158.     glutSolidCube(1.0);
  159.   else
  160.     glutWireCube(1.0);
  161.   glPopMatrix();
  162. }
  163.  
  164. /**********************************************************/
  165. void draw_leg_C(int which, int solid)
  166. {
  167.   glPushMatrix();
  168.   if (which == 0)
  169.     glTranslatef(TORSO_WIDTH_C/4.0, 0.0, 0.0);
  170.   else glTranslatef(-TORSO_WIDTH_C/4.0, 0.0, 0.0);
  171.   /* Upper leg: rotates about the x axis only */
  172.   glColor3f(1.0, 0.0, 0.0);
  173.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  174.   glPushMatrix();
  175.   glTranslatef(0.0, -UPPER_LEG_SIZE_C/2.0, 0.0);
  176.   glScalef(LEG_GIRTH_C, UPPER_LEG_SIZE_C, LEG_GIRTH_C);
  177.   if (solid)
  178.     glutSolidCube(1.0);
  179.   else
  180.     glutWireCube(1.0);
  181.   glPopMatrix();
  182.  
  183.   /* Lower leg: rotates about the x axis only */
  184.   glColor3f(0.0, 1.0, 0.0);
  185.   glTranslatef(0.0, -(UPPER_LEG_SIZE_C+LOWER_LEG_SIZE_C)/2.0, 0.0);
  186.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  187.   glPushMatrix();
  188.   glTranslatef(0.0, -LOWER_LEG_SIZE_C/2.0, 0.0);
  189.   glScalef(LEG_GIRTH_C, LOWER_LEG_SIZE_C, LEG_GIRTH_C);
  190.   if (solid)
  191.     glutSolidCube(1.0);
  192.   else
  193.     glutWireCube(1.0);
  194.   glPopMatrix();
  195.  
  196.   /* Foot: rotates about the x axis only */
  197.   glColor3f(0.0, 0.0, 1.0);
  198.  
  199.   glTranslatef(0.0, -(UPPER_LEG_SIZE_C+LOWER_LEG_SIZE_C+LEG_GIRTH_C)/2.0, 0.0);
  200.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  201.   glPushMatrix();
  202.   glTranslatef(0.0, -LEG_GIRTH_C/2.0, -FOOT_SIZE_C/4.0);
  203.   glScalef(LEG_GIRTH_C, LEG_GIRTH_C, FOOT_SIZE_C);
  204.   if (solid)
  205.     glutSolidCube(1.0);
  206.   else
  207.     glutWireCube(1.0);
  208.   glPopMatrix();
  209.  
  210.   glPopMatrix();
  211. }
  212.  
  213. /*********************************************************************/
  214. void draw_arm_C(int which, int solid)
  215. {
  216.   int arm_which;
  217.  
  218.   if (which == 1)
  219.     arm_which = 1;
  220.   else arm_which = 0;
  221.  
  222.   glPushMatrix();
  223.   glTranslatef(0.0, TORSO_HEIGHT_C, 0.0);
  224.   if (which == 0)
  225.     glTranslatef(TORSO_WIDTH_C/1.5, 0.0, 0.0);
  226.   else glTranslatef(-TORSO_WIDTH_C/1.5, 0.0, 0.0);
  227.   /* Upper leg: rotates about the x axis only */
  228.   glColor3f(1.0, 0.0, 0.0);
  229.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  230.   glPushMatrix();
  231.   glTranslatef(0.0, -UPPER_ARM_SIZE_C/2.0, 0.0);
  232.   glScalef(ARM_GIRTH_C, UPPER_ARM_SIZE_C, ARM_GIRTH_C);
  233.   if (solid)
  234.     glutSolidCube(1.0);
  235.   else
  236.     glutWireCube(1.0);
  237.   glPopMatrix();
  238.  
  239.   /* Lower leg: rotates about the x axis only */
  240.   glColor3f(0.0, 1.0, 0.0);
  241.   glTranslatef(0.0, -(UPPER_ARM_SIZE_C+LOWER_ARM_SIZE_C)/2.0, 0.0);
  242.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  243.   glPushMatrix();
  244.   glTranslatef(0.0, -LOWER_ARM_SIZE_C/2.0, 0.0);
  245.   glScalef(ARM_GIRTH_C, LOWER_ARM_SIZE_C, ARM_GIRTH_C);
  246.   if (solid)
  247.     glutSolidCube(1.0);
  248.   else
  249.     glutWireCube(1.0);
  250.   glPopMatrix();
  251.  
  252.   glPopMatrix();
  253. }
  254.  
  255.  
  256.  
  257.  
  258. GLUquadricObj *quadObj;
  259. GLuint body_lists;
  260.  
  261. /**************************************************************/
  262. void StoreTheGuy_SL(void)
  263. {
  264.   quadObj = gluNewQuadric();
  265.  
  266.   body_lists = glGenLists(NUM_BODY_PARTS);
  267.  
  268.   glNewList(body_lists, GL_COMPILE);
  269.   store_head_SL();
  270.   glEndList();
  271.  
  272.   glNewList(body_lists+1, GL_COMPILE);
  273.   store_torso_SL();
  274.   glEndList();
  275.  
  276.   glNewList(body_lists+2, GL_COMPILE);
  277.   store_uleg_SL();
  278.   glEndList();
  279.  
  280.   glNewList(body_lists+3, GL_COMPILE);
  281.   store_lleg_SL();
  282.   glEndList();
  283.  
  284.   glNewList(body_lists+4, GL_COMPILE);
  285.   store_foot_SL();
  286.   glEndList();
  287.  
  288.   glNewList(body_lists+5, GL_COMPILE);
  289.   store_uarm_SL();
  290.   glEndList();
  291.  
  292.   glNewList(body_lists+6, GL_COMPILE);
  293.   store_larm_SL();
  294.   glEndList();
  295.  
  296. }
  297.  
  298. /**********************************************************/
  299. void store_head_SL(void)
  300.   glPushMatrix();
  301.   glTranslatef(0.0, TORSO_HEIGHT+HEAD_SIZE, 0.0);
  302.   glScalef(HEAD_SIZE, HEAD_SIZE, LEG_GIRTH);
  303.   glutSolidSphere(1.0, SLICES, STACKS);
  304.   glPopMatrix();
  305. }
  306.  
  307. /**********************************************************/
  308. void store_torso_SL(void)
  309. {
  310.   glPushMatrix();
  311.   glScalef(TORSO_WIDTH, TORSO_HEIGHT, LEG_GIRTH);
  312.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  313.   gluCylinder(quadObj, TORSO_TAPER, 1.0, 1.0, SLICES, STACKS);
  314.   glPopMatrix();
  315. }
  316.  
  317. /**************************************************************/
  318. void store_uleg_SL(void)
  319. {
  320.   glPushMatrix();
  321.   glScalef(LEG_GIRTH, UPPER_LEG_SIZE, LEG_GIRTH);
  322.   glRotatef(90.0, 1.0, 0.0, 0.0);
  323.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  324.   glPopMatrix();
  325. }
  326.   
  327. /**************************************************************/
  328. void store_lleg_SL(void)
  329. {
  330.   glPushMatrix();
  331.   glScalef(LEG_GIRTH, LOWER_LEG_SIZE, LEG_GIRTH);
  332.   glRotatef(90.0, 1.0, 0.0, 0.0);
  333.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  334.   glPopMatrix();
  335. }
  336.   
  337. /**************************************************************/
  338. void store_foot_SL(void)
  339. {
  340.   glPushMatrix();
  341.   glTranslatef(0.0, 0.0, -FOOT_SIZE/2.0);
  342.   glScalef(LEG_GIRTH, LEG_GIRTH, FOOT_SIZE);
  343.   glRotatef(90.0, 1.0, 0.0, 0.0);
  344.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  345.   glPopMatrix();
  346. }
  347.   
  348. /**************************************************************/
  349. void store_uarm_SL(void)
  350. {
  351.   glPushMatrix();
  352.   glScalef(ARM_GIRTH, UPPER_ARM_SIZE, ARM_GIRTH);
  353.   glRotatef(90.0, 1.0, 0.0, 0.0);
  354.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  355.   glPopMatrix();
  356. }
  357.   
  358. /**************************************************************/
  359. void store_larm_SL(void)
  360. {
  361.   glPushMatrix();
  362.   glScalef(ARM_GIRTH, LOWER_ARM_SIZE, ARM_GIRTH);
  363.   glRotatef(90.0, 1.0, 0.0, 0.0);
  364.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  365.   glPopMatrix();
  366. }
  367.   
  368. /**************************************************************/
  369. void DrawTheGuy_SL(void)
  370. {
  371.   GLfloat head_diffuse[] =  { 0.7, 0.7, 0.0, 1.0 };
  372.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  373.   GLfloat leg_diffuse[] =   { 0.7, 0.0, 0.7, 1.0 };
  374.   GLfloat arm_diffuse[] =   { 0.7, 0.4, 0.4, 1.0 };
  375.  
  376.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  377.   draw_head_SL();
  378.  
  379.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  380.   draw_torso_SL();
  381.  
  382.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  383.   draw_leg_SL(0);
  384.   draw_leg_SL(1);
  385.  
  386.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  387.   draw_arm_SL(0);
  388.   draw_arm_SL(1);
  389.  
  390. }
  391.  
  392. /**********************************************************/
  393. void draw_head_SL(void)
  394. {
  395.   glPushMatrix();
  396.   glCallList(body_lists);
  397.   glPopMatrix();
  398. }
  399.  
  400. /**********************************************************/
  401. void draw_torso_SL(void)
  402. {
  403.   glPushMatrix();
  404.   glCallList(body_lists+1);
  405.   glPopMatrix();
  406. }
  407.  
  408. /**********************************************************/
  409. void draw_leg_SL(int which)
  410. {
  411.   glPushMatrix();
  412.   if (which == 0)
  413.     glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  414.   else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  415.   /* Upper leg: rotates about the x axis only */
  416.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  417.   glPushMatrix();
  418.   glCallList(body_lists+2);
  419.   glPopMatrix();
  420.  
  421.   /* Lower leg: rotates about the x axis only */
  422.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE)/2.0, 0.0);
  423.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  424.   glPushMatrix();
  425.   glCallList(body_lists+3);
  426.   glPopMatrix();
  427.  
  428.   /* Foot: rotates about the x axis only */
  429.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LEG_GIRTH)/2.0, 0.0);
  430.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  431.   glPushMatrix();
  432.   glCallList(body_lists+4);
  433.   glPopMatrix();
  434.  
  435.   glPopMatrix();
  436. }
  437.  
  438. /*********************************************************************/
  439. void draw_arm_SL(int which)
  440. {
  441.   int arm_which;
  442.  
  443.   if (which == 1)
  444.     arm_which = 1;
  445.   else arm_which = 0;
  446.  
  447.   glPushMatrix();
  448.   glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  449.   if (which == 0)
  450.     glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  451.   else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  452.   /* Upper leg: rotates about the x axis only */
  453.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  454.   glPushMatrix();
  455.   glCallList(body_lists+5);
  456.   glPopMatrix();
  457.  
  458.   /* Lower leg: rotates about the x axis only */
  459.   glTranslatef(0.0, -(UPPER_ARM_SIZE+LOWER_ARM_SIZE)/2.0, 0.0);
  460.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  461.   glPushMatrix();
  462.   glCallList(body_lists+6);
  463.   glPopMatrix();
  464.  
  465.   glPopMatrix();
  466. }
  467.  
  468.  
  469.  
  470. GLUquadricObj *quadObj2;
  471. GLuint body_lists2;
  472.  
  473. /**************************************************************/
  474. void StoreTheGuy_SL2(void)
  475. {
  476.   quadObj2 = gluNewQuadric();
  477.  
  478.   body_lists2 = glGenLists(NUM_BODY_PARTS);
  479.  
  480.   glNewList(body_lists2, GL_COMPILE);
  481.   store_head_SL2();
  482.   glEndList();
  483.  
  484.   glNewList(body_lists2+1, GL_COMPILE);
  485.   store_torso_SL2();
  486.   glEndList();
  487.  
  488.   glNewList(body_lists2+2, GL_COMPILE);
  489.   store_uleg_SL2();
  490.   glEndList();
  491.  
  492.   glNewList(body_lists2+3, GL_COMPILE);
  493.   store_lleg_SL2();
  494.   glEndList();
  495.  
  496.   glNewList(body_lists2+4, GL_COMPILE);
  497.   store_foot_SL2();
  498.   glEndList();
  499.  
  500.   glNewList(body_lists2+5, GL_COMPILE);
  501.   store_uarm_SL2();
  502.   glEndList();
  503.  
  504.   glNewList(body_lists2+6, GL_COMPILE);
  505.   store_larm_SL2();
  506.   glEndList();
  507.  
  508. }
  509.  
  510. /**********************************************************/
  511. void store_head_SL2(void)
  512.   glPushMatrix();
  513.   glTranslatef(0.0, TORSO_HEIGHT+HEAD_SIZE, 0.0);
  514.   glScalef(HEAD_SIZE, HEAD_SIZE, UPPER_LEG_GIRTH);
  515.   glutSolidSphere(1.0, SLICES, STACKS);
  516.   glPopMatrix();
  517. }
  518.  
  519. /**********************************************************/
  520. void store_torso_SL2(void)
  521. {
  522.   glPushMatrix();
  523.   glScalef(TORSO_WIDTH, TORSO_HEIGHT, UPPER_LEG_GIRTH);
  524.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  525.   gluCylinder(quadObj2, TORSO_TAPER, 1.0, 1.0, SLICES, STACKS);
  526.   glPopMatrix();
  527. }
  528.  
  529. /**************************************************************/
  530. void store_uleg_SL2(void)
  531. {
  532.   glPushMatrix();
  533.   glTranslatef(0.0, -(HIP_JOINT_SIZE+UPPER_LEG_SIZE), 0.0);
  534.   glutSolidSphere(KNEE_JOINT_SIZE, SLICES, STACKS);
  535.   glPopMatrix();
  536.   glTranslatef(0.0, -HIP_JOINT_SIZE, 0.0);
  537.   glutSolidSphere(HIP_JOINT_SIZE, SLICES, STACKS);
  538.   glPushMatrix();
  539.   glScalef(UPPER_LEG_GIRTH, UPPER_LEG_SIZE, UPPER_LEG_GIRTH);
  540.   glRotatef(90.0, 1.0, 0.0, 0.0);
  541.   gluCylinder(quadObj2, 1.0, UPPER_LEG_TAPER, 1.0, SLICES, STACKS);
  542.   glPopMatrix();
  543. }
  544.   
  545. /**************************************************************/
  546. void store_lleg_SL2(void)
  547. {
  548.   glPushMatrix();
  549.   glScalef(LOWER_LEG_GIRTH, LOWER_LEG_SIZE, LOWER_LEG_GIRTH);
  550.   glRotatef(90.0, 1.0, 0.0, 0.0);
  551.   gluCylinder(quadObj2, 1.0, LOWER_LEG_TAPER, 1.0, SLICES, STACKS);
  552.   glPopMatrix();
  553. }
  554.   
  555. /**************************************************************/
  556. void store_foot_SL2(void)
  557. {
  558.   glPushMatrix();
  559.   glTranslatef(0.0, 0.0, -FOOT_SIZE/2.0);
  560.   glScalef(LOWER_LEG_GIRTH, LOWER_LEG_GIRTH, FOOT_SIZE);
  561.   glRotatef(90.0, 1.0, 0.0, 0.0);
  562.   gluCylinder(quadObj2, 1.0, 1.0, 1.0, SLICES, STACKS);
  563.   glPopMatrix();
  564. }
  565.   
  566. /**************************************************************/
  567. void store_uarm_SL2(void)
  568. {
  569.   glPushMatrix();
  570.   glTranslatef(0.0, -(SHOULDER_JOINT_SIZE+UPPER_ARM_SIZE), 0.0);
  571.   glutSolidSphere(ELBOW_JOINT_SIZE, SLICES, STACKS);
  572.   glPopMatrix();
  573.   glTranslatef(0.0, -SHOULDER_JOINT_SIZE, 0.0);
  574.   glutSolidSphere(SHOULDER_JOINT_SIZE, SLICES, STACKS);
  575.   glPushMatrix();
  576.   glScalef(UPPER_ARM_GIRTH, UPPER_ARM_SIZE, UPPER_ARM_GIRTH);
  577.   glRotatef(90.0, 1.0, 0.0, 0.0);
  578.   gluCylinder(quadObj2, 1.0, UPPER_ARM_TAPER, 1.0, SLICES, STACKS);
  579.   glPopMatrix();
  580. }
  581.   
  582. /**************************************************************/
  583. void store_larm_SL2(void)
  584. {
  585.   glPushMatrix();
  586.   glScalef(LOWER_ARM_GIRTH, LOWER_ARM_SIZE, LOWER_ARM_GIRTH);
  587.   glRotatef(90.0, 1.0, 0.0, 0.0);
  588.   gluCylinder(quadObj2, 1.0, LOWER_ARM_TAPER, 1.0, SLICES, STACKS);
  589.   glPopMatrix();
  590. }
  591.  
  592. /**************************************************************/
  593. void DrawTheGuy_SL2(void)
  594. {
  595.   GLfloat head_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  596.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  597.   GLfloat leg_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  598.   GLfloat arm_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  599.  
  600.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  601.   draw_head_SL2();
  602.  
  603.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  604.   draw_torso_SL2();
  605.  
  606.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  607.   draw_leg_SL2(0);
  608.   draw_leg_SL2(1);
  609.  
  610.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  611.   draw_arm_SL2(0);
  612.   draw_arm_SL2(1);
  613.  
  614. }
  615.  
  616. /**********************************************************/
  617. void draw_head_SL2(void)
  618. {
  619.   glPushMatrix();
  620.   glCallList(body_lists2);
  621.   glPopMatrix();
  622. }
  623.  
  624. /**********************************************************/
  625. void draw_torso_SL2(void)
  626. {
  627.   glPushMatrix();
  628.   glCallList(body_lists2+1);
  629.   glPopMatrix();
  630. }
  631.  
  632. /**********************************************************/
  633. void draw_leg_SL2(int which)
  634. {
  635.   glPushMatrix();
  636.   if (which == 0)
  637.     glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  638.   else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  639.   /* UPPER leg: rotates about the x axis only */
  640.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  641.   glPushMatrix();
  642.   glCallList(body_lists2+2);
  643.   glPopMatrix();
  644.  
  645.   /* LOWER leg: rotates about the x axis only */
  646.   glTranslatef(0.0, -(UPPER_LEG_SIZE+KNEE_JOINT_SIZE), 0.0);
  647.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  648.   glPushMatrix();
  649.   glCallList(body_lists2+3);
  650.   glPopMatrix();
  651.  
  652.   /* Foot: rotates about the x axis only */
  653.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LOWER_LEG_GIRTH)/2.0, 0.0);
  654.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  655.   glPushMatrix();
  656.   glCallList(body_lists2+4);
  657.   glPopMatrix();
  658.  
  659.   glPopMatrix();
  660. }
  661.  
  662. /*********************************************************************/
  663. void draw_arm_SL2(int which)
  664. {
  665.   int arm_which;
  666.  
  667.   if (which == 1)
  668.     arm_which = 1;
  669.   else arm_which = 0;
  670.  
  671.   glPushMatrix();
  672.   glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  673.   if (which == 0)
  674.     glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  675.   else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  676.   /* UPPER leg: rotates about the x axis only */
  677.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  678.   glPushMatrix();
  679.   glCallList(body_lists2+5);
  680.   glPopMatrix();
  681.  
  682.   /* LOWER leg: rotates about the x axis only */
  683.   glTranslatef(0.0, -(UPPER_ARM_SIZE+ELBOW_JOINT_SIZE), 0.0);
  684.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  685.   glPushMatrix();
  686.   glCallList(body_lists2+6);
  687.   glPopMatrix();
  688.  
  689.   glPopMatrix();
  690. }
  691.  
  692.